package com.kkshop.service.impl;

import org.apache.log4j.Logger;
import org.springframework.transaction.support.TransactionCallback;
import org.springframework.transaction.support.TransactionTemplate;

import com.kkshop.service.TransactionService;

public class TransactionServiceImpl implements TransactionService {
    
    private static final Logger log = Logger.getLogger(TransactionServiceImpl.class);
    
    private TransactionTemplate transactionTemplate;

    public Object doInTransaction(TransactionCallback callback) {
        if(log.isDebugEnabled()) {
            log.debug("Executing in transaction...");
        }
        
        Object result =  transactionTemplate.execute(callback);
        
        if(log.isDebugEnabled()) {
            log.debug("Executing in transaction done");
        }
        
        return result;
    }
    
    public TransactionTemplate geTransactionTemplate() {
        return transactionTemplate;
    }
    
    public void setTransactionTemplate(TransactionTemplate transactionTemplate) {
        this.transactionTemplate = transactionTemplate;
    }
}
